#include "clock_manager.h"
#include "analog_clock.h"

bool maybeUpdateClock(Panel &panel, NTPTime &ntpTime, unsigned long &lastClockUpdate, unsigned long clockIntervalMs) {
    if (millis() - lastClockUpdate <= clockIntervalMs) return false;
    lastClockUpdate = millis();

    uint8_t hour, minute, second;
    if (ntpTime.isTimeValid()) {
        hour = ntpTime.getHour();
        minute = ntpTime.getMinute();
        second = ntpTime.getSecond();
    } else {
        unsigned long totalSeconds = millis() / 1000;
        second = totalSeconds % 60;
        minute = (totalSeconds / 60) % 60;
        hour = (totalSeconds / 3600) % 24;
    }

    // Draw the clock in the left square area
    drawAnalogClock(panel, 0, 0, panel.height, panel.height, hour, minute, second);
    return true;
}
